package org.fatmansoft.teach.models;

import lombok.*;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Set;

/**
 * Course 课程表实体类  保存课程的的基本信息信息，
 * Integer courseId 人员表 course 主键 course_id
 * String num 课程编号
 * String name 课程名称
 * Integer credit 学分
 * Course preCourse 前序课程 pre_course_id 关联前序课程的主键 course_id
 */
@Entity
@Data
@EqualsAndHashCode(exclude = {"students","homeWorks"})
@Table(	name = "course",
        uniqueConstraints = {
        })
public class Course {
    @Id
    private Integer courseId;

    @NotBlank
    @Size(max = 20)
    private String num;  //课序号

    @Size(max = 50)
    private String name; //课程名称

    private Integer credit; //学分

    private String bookName; //教材名称

    private String homework; //课件

    private String material; //参考资料

    @ManyToOne
    @JoinColumn(name="pre_course_id")
    private Course preCourse;

    @ManyToOne
    @JoinColumn(name = "teacher_id")
    private Teacher teacher;

    @ManyToMany(mappedBy = "courses", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @ToString.Exclude
    private Set<Student> students;

    @OneToMany(mappedBy = "course",cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @ToString.Exclude
    private Set<HomeWork> homeWorks;
}
